﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../lib/html5.js"></script>
    <script type="text/javascript" src="../lib/respond.min.js"></script>
    <script type="text/javascript" src="../lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>出库管理</title>
</head>
<body>
    <div class="pt-5  pl-20 pr-20 pb-20">
        <form id="itemEdit" name="itemEdit" method="post" action="../ashx/spui.ashx" class="form form-horizontal">
            <input type="hidden" class="actionValue" id="editAction" name="action" value="add" />
            <input type="hidden" id="id" name="id" />
            <input type="hidden" id="fgid" name="fgid" value="" />
            <input type="hidden" id="tablename" name="tablename" value="" />
            <input type="hidden" id="tablemidname" name="tablemidname" value="" />
            <!-- <input type="hidden" id="fstate" name="fstate" value="草稿" />-->
            <input type="hidden" id="dataneedtouser" name="dataneedtouser" value="1" /><!--是否要包含通用数据必归属处理-->


            <div class="panel panel-primary">
                <div class="panel-body">
                    <div class="row cl">
                        <label class="form-label col-1">仓库：</label>
                        <div class="formControls col-2">
                            <span class="select-box">
                                <select class="select" size="1" name="fstoreid" id="fstoreid" nullmsg="请选择" onchange="storechange()"></select>
                            </span>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-1">出库类型：</label>
                        <div class="formControls col-3">
                            <input type="hidden" id="ftype" name="ftype" value="出库" />
                            <span class="select-box">
                                <select class="select" size="1" name="fsontype" id="fsontype" nullmsg="请选择"></select>
                            </span>
                        </div>
                        <div class="col-1"></div>
                        <label class="form-label col-1">出库日期：</label>
                        <div class="formControls col-3">
                            <input type="text" class="input-text" name="forderNo" id="forderNo" placeholder="出库日期" />
                        </div>
                        <div class="col-1"></div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-1">说明：</label>
                        <div class="formControls col-3">
                            <input type="text" class="input-text" name="fsontypeinfo" id="fsontypeinfo" placeholder="单据说明、生产订单说明" />
                        </div>
                        <div class="col-1"></div>
                        <label class="form-label col-1">处理方式：</label>
                        <div class="formControls col-2">
                            <span class="select-box">
                                <select class="select" size="1" name="fstate" id="fstate">
                                    <option value="提交出库">同步库存</option>
                                    <option value="待出库">暂存-不同步库存</option>
                                    <option value="完成">完成-不会再同步库存</option>
                                </select>
                            </span>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-1">交接人：</label>
                        <div class="formControls col-3">
                            <input type="text" class="input-text" name="finoutusername" id="finoutusername" readonly="readonly" placeholder="右边选择或搜索选择" />
                            <input type="hidden" id="finoutuserid" name="finoutuserid" />
                        </div>
                        <div class="col-3 layui-form">
                            <select name="inoutusernamesel" id='inoutusernamesel' lay-filter="testselect" lay-verify="required" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel panel-primary">
                <div class="panel-body">
                    <div class="row cl">
                        <div class=" col-12">
                            <label class="form-label col-1">天气：</label>
                            <div class="formControls  skin-minimal col-5">
                                <div class="radio-box">
                                    <input type="radio" id="workfinfofv4" name="workfinfofv4" value="晴天" class="hcradio" checked="checked" />
                                    <label for="workfinfofv4">晴天</label>
                                </div>
                                <div class="radio-box">
                                    <input type="radio" id="workfinfofv42" name="workfinfofv4" value="阴天" />
                                    <label for="workfinfofv42">阴天</label>
                                </div>
                                <div class="radio-box">
                                    <input type="radio" id="workfinfofv43" name="workfinfofv4" value="雨天" />
                                    <label for="workfinfofv43">雨天</label>
                                </div>
                                <div class="radio-box">
                                    <input type="radio" id="workfinfofv44" name="workfinfofv4" value="其它" />
                                    <label for="workfinfofv44">其它</label>
                                </div>
                            </div>
                            <div class="formControls col-1">作业目标：</div>
                            <div class="formControls col-4">
                                <button onclick="bshcrainselectdcinfo();" class="btn btn-danger radius" type="button">选择地块</button>
                                <button onclick="bshcrainselecttaskinfo();" class="btn btn-danger radius" type="button">选择任务</button>
                            </div>
                            <label class="form-label col-1" style="display: none;">目标：</label>
                            <div class="formControls  skin-minimal col-5" style="display: none;">
                                <div class="radio-box">
                                    <input type="radio" id="radioworkfordcnull" name="raditworkforwhat" value="2" checked="checked" class="hcradio" />
                                    <label for="radioworkfordcnull">地块空地</label>
                                </div>
                                <div class="radio-box">
                                    <input type="radio" id="radioworkforall" name="raditworkforwhat" value="0" />
                                    <label for="radioworkforall">整个地块</label>
                                </div>
                                <div class="radio-box">
                                    <input type="radio" id="raditworkfordc" name="raditworkforwhat" value="1" />
                                    <label for="raditworkfordc">地块的任务</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">


                        <div class="formControls col-12">
                            <input type="hidden" class="input-text" placeholder="地块任务信息" name="fdctaskinfo" id="fdctaskinfo" value="" />
                            <input type="hidden" class="input-text" placeholder="地id" name="idbshcrainselectdcinfo" id="idbshcrainselectdcinfo" value="" />
                            <!--<input type="text" readonly="readonly" class="input-text" placeholder="地/任务 信息" name="namebshcrainselectdcinfo" id="" value="" />-->
                            <textarea readonly="readonly" name="namebshcrainselectdcinfo" id="namebshcrainselectdcinfo" cols="" rows="" class="textarea" placeholder="地/任务 信息－－－不支持地块 和 任务 混合选择"></textarea>

                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-1">作业类型：</label>
                        <div class="formControls col-2 layui-form" readonly="readonly">
                            <select name="workfinfotypeid" id='workfinfotypeid' lay-filter="workfinfotypeid" lay-search="" readonly="readonly">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                            <!-- <input type="hidden" id="finfotypeid" name="finfotypeid" value="" />-->
                            <input type="hidden" id="workfinfotypename" name="workfinfotypename" value="" />
                            <input type="hidden" id="workfinfotype" name="workfinfotype" value="" />
                            <input type="hidden" id="workfinfobytype1" name="workfinfobytype1" value="" />
                        </div>
                        <label class="form-label col-1">作业时间：</label>
                        <div class="formControls col-2">
                            <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="workfinfodt1" id="workfinfodt1" class="input-text Wdate" />
                        </div>

                        <label class="form-label col-1" style="display: none;">结束时间：</label>
                        <div class="formControls col-2" style="display: none;">
                            <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})" name="workfinfodt2" id="workfinfodt2" class="input-text Wdate" />
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-1">作业工具：</label>
                        <div class="col-2 layui-form">
                            <select name="workfinfofv5" id='workfinfofv5' lay-filter="testselect2" lay-verify="required" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                        </div>
                        <label class="form-label col-1">作业说明：</label>
                        <div class="formControls col-5">
                            <input type="text" class="input-text" name="workfinfofv6" id="workfinfofv6" />
                        </div>
                    </div>

                    <div class="row cl" id="divshowdivinfofv10" style="display: none;">
                        <!--植保特殊数据-->
                        <label class="form-label col-1">防治对象：</label>
                        <div id="divinfofv10">
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-primary">
                <div class="panel-body">
                    <div class="row cl layui-form">
                        <div class="formControls col-2">
                            分类
                            <select name="selfproducttype" id='selfproducttype' lay-filter="testselectfl" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                        </div>
                        <div class="col-2">
                            物品
                            <select name="selherp_product" id='selherp_product' lay-filter="selherp_product" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                        </div>
                        <div class="col-8">
                            生产批号
                            <select name="selherp_productpc" id='selherp_productpc' lay-filter="selherp_productpc" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                        </div>

                        <input type="hidden" class="input-text" name="selprice" placeholder="单价" id="selprice" />
                        <input type="hidden" name="selspbasecdate" id="selspbasecdate" class="input-text" />
                        <input type="hidden" class="input-text" name="selspbasecj" placeholder="厂家" id="selspbasecj" />
                        <input type="hidden" class="input-text" name="selunit" id="selunit" value="单位" placeholder="2~10个字符" />
                        <input type="hidden" class="input-text" name="selspbasezj" placeholder="资质" id="selspbasezj" />
                        <input type="hidden" class="input-text" name="selspbasepc" placeholder="批次" id="selspbasepc" />
                        <input type="hidden" class="input-text" name="sellistid" placeholder="库存明细ID" id="sellistid" />
                        <input type="hidden" class="input-text" name="sellistidkc" placeholder="库存" id="sellistidkc" />
                    </div>
                    <div class="row cl">
                        <div class="formControls col-2">
                            出库数量(<label id="lable_dw"></label>)
                            <input type="text" class="input-text" placeholder="出库数量" name="selcount" id="selcount" value="1" />
                        </div>
                        <div class="formControls col-2">
                            说明：
                            <input type="text" class="input-text" name="selspbasedesc" placeholder="说明" id="selspbasedesc" />
                        </div>

                        <div class="formControls col-2">
                            <br />
                            <button onclick="addOrderSpListInfo();" class="btn btn-danger radius" type="button">添加</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-success">
                <div class="panel-header">出库列表</div>
                <div id="tableArea">
                    <table class="table table-border table-bordered table-striped table-hover" id="tablelist">
                        <thead>
                            <tr class="text-c">
                                <th width="30"><a id="hcmtable_sall" onclick="hcmtable_sall();" href="javascript:;" title="全选反选"><i class="Hui-iconfont">&#xe608;全</i></a></th>

                                <th>主分类</th>
                                <th>名称</th>
                                <th>金额</th>
                                <th>数量</th>
                                <th>单位</th>
                                <th>厂家</th>
                                <th>资质</th>
                                <th>批次</th>
                                <th>生产日期</th>
                                <th>说明</th>

                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>



            <div class="row cl">
                <div class="col-6 col-offset-4">
                    <!--  <button onclick="changeshowtype();" class="btn btn-danger radius" type="button">切换显示</button>&nbsp;&nbsp;&nbsp;&nbsp;-->
                    <button class="btn btn-primary radius" type="submit" id="btsub1">保存</button>&nbsp;&nbsp;
                    <button class="btn btn-secondary radius" type="button" id="btn_reset">重置</button>&nbsp;&nbsp;
                    <button onclick="layer_close();" class="btn btn-default radius" type="button">返回</button>
                </div>
            </div>
            <input type="hidden" id="raditworkforwhatnew" name="raditworkforwhatnew" value="" />
        </form>
    </div>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="../lib/Validform/5.3.2/Validform.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_au.js"></script>
    <script type="text/javascript" src="../js/hcrainwf.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>

    <script type="text/javascript" src="../lib/datatables/1.10.0/jtable.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>
    <!--以下为多选择下拉ggggggggggggg-->
    <!--    <link rel="stylesheet" href="../homepage/css/bootstrap.min.css" type="text/css" />
    <script type="text/javascript" src="../homepage/js/bootstrap.min.js"></script>

    <script type="text/javascript" src="../homepage/js/bootstrap-multiselect.js"></script>
    <link rel="stylesheet" href="../homepage/css/bootstrap-multiselect.css" type="text/css" />-->
    <script type="text/javascript">
        $("#workfinfodt1").val((new Date()).Format("yyyy-MM-dd"));//开始时间
        $("#workfinfodt2").val((new Date()).Format("yyyy-MM-dd 23:59:59"));//结束时间
        hcui_ajaxasync = false;

        var uiform = null;
        var divshowtype = 1;
        //初始化

        $('#fsontype').append('<option value="生产取料">生产取料-出库</option>');
        $('#fsontype').append('<option value="发货出库">发货出库-出库</option>');
        $('#fsontype').append('<option value="销售出库">销售出库-出库</option>');
        $('#fsontype').append('<option value="其它出库">其它出库-出库</option>');

        //本页面
        spsetBase("herp_inoutorder", "id", "herp_inoutorder as T", "*", "#tablelist", "herp_inoutorder", "出入库管理", "StoreInOut");


        //当前关联对象信息--人员
        var inoutusernameselObj = [];
        //当前关联对象信息--物品
        var inoutproductObj = [];
        //当前关联对象信息--物品
        var inoutproductObj2 = [];
        var selectworktypeinfo = [];//作业信息
        //加载处理
        function loadin() {
            layui.use(['form'], function () {
                uiform = layui.form();

                if (getUrlParam("action") == "add") {
                    $("#fgid").val(NewGuid());
                    table_reset();
                }
                //作业类型
                hcdoselbyPost("id,fv1 as name,fv3,fv4", "yw_baseinfo", "type='4' and  maintype='4' and fv3<>'1' and fv3 in ('4','7','8')", "", "", "id",
                 function (data) {
                     SetSelectWithArrayIdName("#workfinfotypeid", data);
                     selectworktypeinfo = data;
                     //$("#workfinfotypeid").val(getUrlParam("urlworktype"));
                     if (uiform) uiform.render('select');
                 });

                uiform.on('select(testselect)', function (data) {//选择交接人处理
                    $('#finoutuserid').val(data.value);
                    $('#finoutusername').val($("#inoutusernamesel").find("option:selected").text());
                });

                uiform.on('select(testselectfl)', function (sdata) {//分类选择处理--加载分类明细
                    hcdoselbyPost("id,concat(productno) as name,unit", "herp_product", "producttype='" + sdata.value + "' and databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                        SetSelectWithArrayIdName("#selherp_product", data);
                        inoutproductObj = data;
                        uiform.render('select');
                        $("#sellistid").val("");
                    });

                });

                uiform.on('select(selherp_product)', function (sdata) {//物品选择处理--加载 库存明细
                    if ($("#fstoreid").val() == "") {
                        layer.msg('仓库不能为空', { icon: 1 });
                        return;
                    }
                    var unit = hcgetJsonObjById(inoutproductObj, sdata.value).unit;
                    $('#lable_dw').text(unit);
                    hcdoselbyPost("id,concat('批次:',spbasepc,'-厂家:',spbasecj,'-单价：',price,'-库存：',count-hasout,'-生产日期:',case when spbasecdate  is null  then '' else DATE_FORMAT(spbasecdate,'%Y-%m-%d') END ) as name,spbasepc,spbasecj,spbasecdate,unit,price,spbasezj,count-hasout as countnew", "herp_inoutorderlist", "databranchid='" + HCUser.HCUorg + "'    and spid=" + sdata.value + " and storeid =" + $("#fstoreid").val() + " and datastate='入库' and count-hasout>0", "", "", "dataaddtime asc", function (data) {
                        SetSelectWithArrayIdName("#selherp_productpc", data);
                        inoutproductObj2 = data;
                        uiform.render('select');
                        $("#sellistid").val("");
                    });

                });
                uiform.on('select(selherp_productpc)', function (data) {
                    $('#selprice').val(hcgetJsonObjById(inoutproductObj2, data.value).price);
                    $('#selspbasecdate').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasecdate);
                    $('#selspbasecj').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasecj);
                    $('#selspbasezj').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasezj);
                    $('#selunit').val(hcgetJsonObjById(inoutproductObj2, data.value).unit);
                    $('#sellistid').val(hcgetJsonObjById(inoutproductObj2, data.value).id);
                    $('#sellistidkc').val(hcgetJsonObjById(inoutproductObj2, data.value).countnew);
                    $('#selspbasepc').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasepc);

                });

                //下拉加载-仓库
                hcdoselbyPost("id,name", "herp_storehouse", "databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                    SetSelectWithArrayIdName("#fstoreid", data);
                    $('#fstoreid option:eq(1)').attr('selected', 'selected');//选择第二(1)个
                });

                //下拉加载 --物品主分类
                hcdoselbyPost("dictdata_code as id,dictdata_name as name", "dictionarydata", "dict_code='ErpProductMtype'", "", "", "orderindex",
                       function (data) {
                           SetSelectWithArrayIdName("#selfproducttype", data);
                           uiform.render('select');
                       });
                //下拉加载 --人员
                hcdoselbyPost("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "branchid='" + HCUser.HCUorg + "'", "", "", "id",
                    function (data) {
                        SetSelectWithArrayIdName("#inoutusernamesel", data);

                        uiform.render('select');
                    });

                //作业类型选择
                uiform.on('select(workfinfotypeid)', function (data) {
                    $('#workfinfotypename').val(hcgetJsonObjById(selectworktypeinfo, data.value).name);
                    $('#workfinfotype').val(hcgetJsonObjById(selectworktypeinfo, data.value).fv3);//一级
                    $('#workfinfobytype1').val(hcgetJsonObjById(selectworktypeinfo, data.value).fv4);//二级
                    if ($('#workfinfotype').val() == "8") {
                        $("#divshowdivinfofv10").show();
                        //$("#workfinfofv6").val("打药作物收货安全间隔期:鱼藤酮5天,BS/BT/5%除虫菊素7天");
                    }
                    else { $("#divshowdivinfofv10").hide(); }
                    //加载作业工具
                    hcdoselbyPost("t1.id  as id,concat(t1.fv3,'-',t1.fv4) as name", "yw_baseinfo as t1  INNER JOIN yw_baseinfo as t2 on  t1.fv1=t2.id", "t1.type=8 and t1.maintype=8 and t1.databranchid=" + HCUser.HCUorg + " and t2.fv3 in(" + $("#workfinfotype").val() + ")", "", "", "t1.id", function (data) {
                        SetSelectWithArrayIdName("#workfinfofv5", data);
                        if (data.length > 0) {
                            $('#workfinfofv5').val(data[0].id);
                        }
                    });
                    if (uiform) uiform.render('select');

                });
            });

            //防治对象
            hcdoselbyPost("t1.id  as id,t1.fv1 as name", "yw_baseinfo as t1", "t1.type=9 and t1.maintype=9 and t1.databranchid=" + HCUser.HCUorg, "", "", "id", function (data) {
                SetCheckBoxsInfo("#divinfofv10", "workfinfofv10", data);
            });
            // $.Huitab("#tab-category .tabBar span", "#tab-category .tabCon", "current", "click", "0");
            //$.Huifold("#Huifold2 .item h4", "#Huifold2 .item .info", "", 3, "click"); /*5个参数顺序不可打乱，分别是：相应区,隐藏显示的内容,速度,类型,事件 mouseover click */
            ////三种类型：分别对应的参数：1	只打开一个，可以全部关闭2	必须有一个打开3	可打开多个

        }
        function loadstoreinfo() {

        }
        function table_reset() {
            hcmtable = $("#tablelist").DataTable({
                "serverSide": true,//服务端处理分页 无法使用当前查找
                "bFilter": false,  //是否使用内置的过滤功能
                "bLengthChange": false, //改变每页显示数据数量
                "ajax": {
                    "type": "POST",
                    "url": sposelUrl("herp_inoutorderlist", "id,totaskinfo,spbasecj,spbasezj,spbasepc,spbasecdate,spbasedesc,gid,ordergid,spid,spname,count,price,state,unit,'desc',storeid,spmaintype,spsubtype,(count * price) as allmoney", " and ordergid='" + $("#fgid").val() + "'") + "&sporderby=id",
                    "data": function (d) {
                    }
                },
                aLengthMenu: [100],
                "columns": [
                      { "data": "rowhcindex" },
                      { "data": "spmaintype" },
        { "data": "spname" },
        { "data": "price" },
        { "data": "count" },
        { "data": "unit" },
        { "data": "spbasecj" },
        { "data": "spbasezj" },
        { "data": "spbasepc" },
        { "data": "spbasecdate" },
        { "data": "spbasedesc" },

      { "data": "id" }

                ],
                "columnDefs": [

                    {
                        "targets": [11],
                        "render": function (data, type, row) {
                            if (loadbackdata.state == '完成')
                            { return "当前状态不能操作"; }
                            else
                                return "<a style=\"text-decoration:none\" class=\"ml-5\" onclick=\"toolDelete('" + data + "','herp_inoutorderlist','id')\"     href=\"javascript:;\" title=\"删除\"><i class=\"Hui-iconfont\">&#xe6e2;删除</i></a>";
                        }
                    },

                {
                    "orderable": false,
                    "targets": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
                }
                ]
            });
        }
        //function loadback(data) {
        //    console.log(data);
        //    $('#ftype').change();//主分类
        //    $("#fsontype").val(data["sontype"]);//重新 设置子分类
        //    $("#finoutusertype").val(data["inoutusertype"]);//重新 对象分类
        //    $('#finoutusertype').change();
        //}
        //切换事件
        function changeshowtype() {
            if (divshowtype == 1) {
                $("#divshow1").appendTo("#divfold1");
                $("#divshow2").appendTo("#divfold2");
                $("#divshow3").appendTo("#divfold3");
                $("#fold_category").show();
                $("#tab-category").hide();

                divshowtype = 2;
            }
            else {
                $("#divshow1").appendTo("#divtab1");
                $("#divshow2").appendTo("#divtab2");
                $("#divshow3").appendTo("#divtab3");
                $("#fold_category").hide();
                $("#tab-category").show();
                divshowtype = 1;
            }

        }

        var oldstate = "待出库";
        var loadbackdata = [];
        //加载完成后,加载明细列表
        function loadback(data) {
            table_reset();
            loadbackdata = data;
            oldstate = loadbackdata.state;
            //if (loadbackdata.state == '完成')//已完成，不能修必出入库状态
            //{
            //    $("#btsub1").hide();
            //}
            if (loadbackdata.state == '完成')//已完成，不能修必出入库状态
            {
                $("#fstate").attr("disabled", "disabled");
            }
            if (getUrlParam("action") == "edit") {
                $("#fstoreid").attr("disabled", "disabled");
            }

        }
        //添加商品明细
        function addOrderSpListInfo() {
            if ($("#fstoreid").val() == "") {
                layer.msg('仓库不能为空', { icon: 1 });
                return;
            }
            if (loadbackdata.state == '完成') {
                layer.msg('当前状态不能操作', { icon: 1 });
                return;
            }
            if ($("#selherp_product").val() == "") {
                layer.msg('请选择物品信息', { icon: 2 });
                return;
            }
            if ($("#sellistid").val() == "") {
                layer.msg('请选择物品批次明细', { icon: 2 });
                return;
            }
            if (!hcisbnum($("#selcount").val())) {
                layer.msg('出库的数值无效', { icon: 2 });
                return;
            }

            if (parseFloat($("#selcount").val()) > parseFloat($("#sellistidkc").val())) {
                layer.msg('当前批次库存不足', { icon: 2 });
                return;
            }
            $("#fstoreid").attr("disabled", "disabled");
            var addinfo = "gid%" + NewGuid()
                + "$ordergid%" + $("#fgid").val()
                + "$spmaintype%" + $("#selfproducttype").find("option:selected").text()
                + "$spid%" + $("#selherp_product").val()
                + "$spname%" + $("#selherp_product").find("option:selected").text()
                + "$count%" + $("#selcount").val()
                + "$price%" + $("#selprice").val()
                 + "$spbasecj%" + $("#selspbasecj").val()
                + "$spbasezj%" + $("#selspbasezj").val()
                + "$spbasepc%" + $("#selspbasepc").val()
                + "$spbasecdate%" + $("#selspbasecdate").val()
              + "$fromid%" + $("#sellistid").val()
             //               + "$totaskid%" + $("#seltaskinfo").val()
            // + "$totaskinfo%" + $("#seltaskinfo").find("option:selected").text()
                 + "$spbasedesc%" + $("#selspbasedesc").val() + "$hasout%0"
            + "$unit%" + $("#selunit").val();
            hcdoadd201702("herp_inoutorderlist", addinfo, 1, "", "fordergid,ffromid#当前记录已在出库列表，可以删除再添加!", function (info) {
                console.log(info);
                if (info == "ok") hcmtable.ajax.reload();
                else {
                    layer.msg(info, { icon: 2 });
                }


            });
        }
        //提交数据后,回调
        function subback(data) {
          
            if (data.status == "y") {
                var showmessage = "处理成功";
                if (loadbackdata.state != '完成' && $("#fstate").val() == "提交出库") {               //分析是否要同步库存
                    //提交同步数据
                    $.ajax({
                        type: "get",
                        url: spPageUrl,
                        data: {
                            "action": "doProc",
                            "procName": "doProcOutorderOK",
                            "hcporderguid": $("#fgid").val()
                        },
                        timeout: 30,
                        async: false,
                        cache: false,
                        error: function () {
                            alert("error");
                        },
                        success: function (re) {
                            var data = JSON.parse(re);
                            if (data.message == JsonResult.Success) {
                                showmessage = data.data;
                                hcapigetNoError("../api/Task/GetStoreTask", {}, function (backdata) {
                                });
                            }
                            else {
                                layer.alert(data.data, { icon: 2 });
                                return;
                            }
                        }
                    });
                    ////生成任务信息
                    //console.log($('input[name="workfinfofv4"]:checked').val());
                    //console.log($('input[name="raditworkforwhat"]:checked').val());
                    //console.log($('#idbshcrainselectdcinfo').val());
                    //console.log($('#namebshcrainselectdcinfo').val());
                    //console.log($('#workfinfotypeid').val());
                    //console.log($('#workfinfotypename').val());
                    //console.log($('#workfinfotype').val());
                    //console.log($('#workfinfobytype1').val());
                    //console.log($('#workfinfodt1').val());
                    //console.log($('#workfinfodt2').val());
                    //console.log($('#workfinfofv5').val());
                    //console.log($('#workfinfofv6').val());
                    var fruit = "";
                    $("input:checkbox[name='workfinfofv10']:checked").each(function () {
                        fruit += $(this).val() + ",";
                    });

                    hcapipost("../api/Hcrain/CreateWorkByStoreOut", {
                        "outgid": $("#fgid").val(),
                        "workfinfofv10": fruit,
                        "workfinfofv4": $('input[name="workfinfofv4"]:checked').val(),
                        "raditworkforwhat": $('#raditworkforwhatnew').val(),
                        // $('input[name="raditworkforwhat"]:checked').val(),//0整个地 1地的任务（不用）2地的空地（不用）3直接指定任务
                        "idbshcrainselectdcinfo": $('#idbshcrainselectdcinfo').val(),
                        "namebshcrainselectdcinfo": $('#namebshcrainselectdcinfo').val(),
                        "workfinfotypeid": $('#workfinfotypeid').val(),
                        "workfinfotypename": $('#workfinfotypename').val(),
                        "workfinfotype": $('#workfinfotype').val(),
                        "workfinfobytype1": $('#workfinfobytype1').val(),
                        "workfinfodt1": $('#workfinfodt1').val(),
                        "workfinfodt2": $('#workfinfodt2').val(),
                        "workfinfofv5": $('#workfinfofv5').val(),
                        "workfinfofv6": $('#workfinfofv6').val(),
                        "workuserName": $('#finoutusername').val(),
                        "workUserId": $('#finoutuserid').val()
                    }, function (data) { });


                }
                if (getUrlParam("action") == "add") {
                    if ($("#fgid")) { $("#fgid").val(NewGuid()); }
                }

                layer.confirm(showmessage, {
                    btn: ['确认'] //按钮
                }, function (index) {
                    layer_close();
                    //layer.msg('继续添加', { icon: 1 });
                    //$("#btn_reset").click();
                    //table_reset();
                }, function (index) {
                    layer_close();
                });


                //layer.alert(data.info, { icon: 1 });

            }
            else {
                layer.alert(data.info, { icon: 2 });
            }
        }
        //重写  提交前数据处理
        function hcrBeforeSub() {

            //alert($('#finoutusername').val());

            if ($('#idbshcrainselectdcinfo').val().length == 0) {
                layer.msg("请选择地块/任务信息", { icon: 5 });
                return false;
            }
            if ($('#workfinfotypename').val().length == 0) {
                layer.msg("作业类型", { icon: 5 });
                return false;
            }
            $("#fstoreid").removeAttr("disabled");
        }
        function storechange() {
            SetSelectWithArrayIdName("#selherp_productpc", []);
            uiform.render('select');
        }

        function bshcrainselectdcinfo() {
            layer.open({
                type: 2,
                skin: 'CLYM-style',
                area: ['100%', '100%'],
                title: '选择地块',
                content: '../ywbase/selectbaseinfo2.html'
            });
        }
        function bshcrainselecttaskinfo() {
            layer.open({
                type: 2,
                skin: 'CLYM-style',
                area: ['100%', '100%'],
                title: '选择任务',
                content: '../ywbase/selectbasetaskinfo.html'
            });
        }
        var selectDcinfo = "";
        //地块／任务信息   类型  ｔｙｐｅ：０地块３直接任务
        function settoolselectObj(selectObj, type) {

            var ids = "";
            var names = "";
            for (var j = 0; j < selectObj.length; j++) {
                ids = ids + selectObj[j].id + ",";
                names = names + selectObj[j].name + ",";
            }
            $("#raditworkforwhatnew").val(type);
            $("#idbshcrainselectdcinfo").val(ids);
            $("#namebshcrainselectdcinfo").val(names);

            $("#fdctaskinfo").val(names);
        }
    </script>
</body>
</html>
